package com.jsp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.jsp.bean.RentcarBean;
import com.jsp.util.DBUtil;


public class RentcarDao {

	public RentcarBean insert(RentcarBean rentcar) throws SQLException {
		Connection con=DBUtil.getConnection();
		
		String sql = "insert into rentcarinformation(apply_name,openTime,returnTime,reason,apply_car,apply_driver,opinion)values(?,?,?,?,?,?,?)";
		PreparedStatement state = con.prepareStatement(sql);
		state.setString(1,rentcar.getApply_name());
		state.setString(2,rentcar.getOpenTime());
		state.setString(3,rentcar.getReturnTime());
		state.setString(4, rentcar.getReason());
		state.setString(5, rentcar.getApply_car());
		state.setString(6, rentcar.getApply_driver());	
		state.setString(7, rentcar.getOpinion());
		state.executeUpdate();
		state.close();
		con.close();
	
	
		return rentcar;
	}
	
	public RentcarBean update(RentcarBean rentcar) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="update rentcarinformation set "
				+ "id=?,apply_name=?,openTime=?,returnTime=?,"
				+ "reason=?,apply_car=?,apply_driver=?,opinion=? where id=?";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, rentcar.getId());
		state.setString(2, rentcar.getApply_name());
		state.setString(3, rentcar.getOpenTime());
		state.setString(4, rentcar.getReturnTime());
		state.setString(5, rentcar.getReason());
		state.setString(6, rentcar.getApply_car());
		state.setString(7, rentcar.getApply_driver());
		state.setString(8, rentcar.getOpinion());
		state.setString(9, rentcar.getId());
		state.executeUpdate();
		state.close();
		con.close();
		
		return rentcar;
		}
	
	public RentcarBean delete(RentcarBean rentcar) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="delete from rentcarinformation where id=?";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, rentcar.getId());
		state.executeUpdate();
		state.close();
		con.close();
		
		return rentcar;
		}
	
}
